﻿using MediatR;
using W.Warehouse.Api.Application.Command.CheckCommand;
using W.Warehouse.Repository.Impl;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.CheckCommandHandler
{
    public class CheckDeleteRangeCommandHandler:IRequestHandler<CheckDeleteRangeCommand,int>
    {
        private readonly ICheckRepository _checkRepositroy;
        public CheckDeleteRangeCommandHandler(ICheckRepository checkRepositroy)
        {
            _checkRepositroy = checkRepositroy;
        }

        public async Task<int> Handle(CheckDeleteRangeCommand request, CancellationToken cancellationToken)
        {
            var list = await _checkRepositroy.GetAllAsync();
            var plist = list.Where(c => request.Ids.Contains(c.CheckId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _checkRepositroy.UpdateRangeAsync(plist);
            return n;
        }
    }
}
